package com.controller;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import com.entity.Dayi;
import com.entity.Course;
import com.entity.Lilun;
import com.entity.Shipin;
import com.entity.Shiyan;
import com.entity.User;
import com.entity.Ziyuan;
import com.service.DayiService;
import com.service.KechengService;
import com.service.LilunService;
import com.service.ShipinService;
import com.service.ShiyanService;
import com.service.UserService;
import com.service.ZiyuanService;
import com.util.Util;



@Controller
@RequestMapping("/")
public class IndexController {

	
	@Resource
	private LilunService lilunService;
	
	@Resource
	private ShiyanService shiyanService;
	
	@Resource
	private KechengService kechengService;
	
	@Resource
	private UserService userService;
	
	@Resource
	private ZiyuanService ziyuanService;
	
	@Resource
	private ShipinService shipinService;
	
	@Resource
	private DayiService dayiService;
	
	
	// 获取输出对象
	public PrintWriter getPrintWriter(HttpServletResponse response) {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return writer;
	}
	
	
	//网站首页
	@RequestMapping("/index.do")
	public String index(HttpServletRequest request,HttpServletResponse response){
		
		
		Map<String,List<Lilun>> lilunmap = lilunService.selectBeanMap(1, 5, "index", " select * from t_lilun order by id desc ");
		String pagerinfo = lilunmap.keySet().iterator().next();
		List<Lilun> lilunlist = lilunmap.get(pagerinfo);
		
		request.setAttribute("lilunlist", lilunlist);
		
		
		Map<String,List<Shiyan>> shiyanmap = shiyanService.selectBeanMap(1, 5, "index", " select * from t_shiyan order by id desc ");
		String pagerinfo2 = shiyanmap.keySet().iterator().next();
		List<Shiyan> shiyanlist = shiyanmap.get(pagerinfo2);
		
		request.setAttribute("shiyanlist", shiyanlist);
	
		
		return "index.jsp";

	}
	
	
	
	//理论教学
	@RequestMapping("/lilunlist.do")
	public String lilunlist(HttpServletRequest request,HttpServletResponse response,String pagenum,String biaoti,String kechengid){
		
		
		String url = "lilunlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_lilun where  ");
		
		//查询条件返回页面
		if (biaoti != null && !"".equals(biaoti)) {

			sb.append(" biaoti like '%"+biaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("biaoti", biaoti);
		}
		
		if (kechengid != null && !"".equals(kechengid)) {

			sb.append(" kechengid ="+kechengid+" ");
			sb.append(" and ");
			
			request.setAttribute("kechengid", kechengid);
		}
		
		
		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Lilun>> map = lilunService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Lilun> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "lilunlist.jsp";

	}
	
	
	//理论教学详情页面
	@RequestMapping("/lilunshow.do")
	public String lilunshow(HttpServletRequest request,int id){

		Lilun bean = lilunService.selectData(" select * from t_lilun where id= "+id).get(0);
		
		bean.setVist(bean.getVist()+1);
		
		lilunService.updateBean(bean);

		request.setAttribute("bean", bean);

		return "lilunshow.jsp";

	}
	
	
	
	//实验教学
	@RequestMapping("/shiyanlist.do")
	public String shiyanlist(HttpServletRequest request,HttpServletResponse response,String pagenum,String biaoti,String kechengid){
		
		
		String url = "shiyanlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_shiyan where  ");
		
		//查询条件返回页面
		if (biaoti != null && !"".equals(biaoti)) {

			sb.append(" biaoti like '%"+biaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("biaoti", biaoti);
		}
		
		if (kechengid != null && !"".equals(kechengid)) {

			sb.append(" kechengid ="+kechengid+" ");
			sb.append(" and ");
			
			request.setAttribute("kechengid", kechengid);
		}
		
		
		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Shiyan>> map = shiyanService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Shiyan> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "shiyanlist.jsp";

	}
	
	
	//实验教学详情页面
	@RequestMapping("/shiyanshow.do")
	public String shiyanshow(HttpServletRequest request,int id){

		Shiyan bean = shiyanService.selectData(" select * from t_shiyan where id= "+id).get(0);
		
		bean.setVist(bean.getVist()+1);
		
		shiyanService.updateBean(bean);

		request.setAttribute("bean", bean);

		return "shiyanshow.jsp";

	}
	
	
	//跳转到学生注册页面
	@RequestMapping("/register.do")
	public String register(HttpServletRequest request){

		return "register.jsp";

	}
	
	
	//学生注册操作
	@RequestMapping("/register2.do")
	public void register2(HttpServletRequest request,HttpServletResponse response,User user){
		
		PrintWriter writer = this.getPrintWriter(response);

		User bean = userService.useryz(user.getUsername());
		
		if(bean!=null){
			
			writer.print("<script language=javascript>alert('该用户名已经存在，注册失败！');window.location.href='register.do';</script>");
		
			return;	
		}

		user.setCtime(Util.getTime());
		user.setRole(3);
		
		userService.insertBean(user);
		
		writer.print("<script language=javascript>alert('注册成功');window.location.href='login.do';</script>");
		

	}
	
	
	//跳转到学生登录页面
	@RequestMapping("/login.do")
	public String login(HttpServletRequest request){

		return "login.jsp";

	}
	
	
	//用户登录操作
	@RequestMapping("/login2.do")
	public void login2(HttpServletRequest request,HttpServletResponse response,String username,String password){
		
		PrintWriter writer = this.getPrintWriter(response);
		
		
		User bean = userService.userlogin(username, password, 3);
		
		if(bean==null){
			bean = userService.userlogin(username, password, 2);
		}
		
		
		if(bean==null){
			
			writer.print("<script language=javascript>alert('用户名或者密码错误，登录失败！');window.location.href='login.do';</script>");
		
			
		}else{
			
			HttpSession session = request.getSession();
			session.setAttribute("qiantai", bean);
			
			writer.print("<script language=javascript>alert('登录成功');window.location.href='.';</script>");
			
		}

	}
	
	
	
	//安全退出操作
	@RequestMapping("/loginout.do")
	public void loginout(HttpServletRequest request,HttpServletResponse response){
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		session.removeAttribute("qiantai");
		
		writer.print("<script language=javascript>alert('退出成功');window.location.href='login.do';</script>");
		

	}
	
	
	
	//跳转到修改密码页面
	@RequestMapping("/password.do")
	public String password(HttpServletRequest request){

		return "password.jsp";

	}
	
	
	//修改密码操作
	@RequestMapping("/password2.do")
	public void password2(HttpServletRequest request,HttpServletResponse response,String password1,String password2){
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		
		User bean = userService.userlogin(user.getUsername(), password1, 2);
		
		if(bean==null){
			bean = userService.userlogin(user.getUsername(), password1, 3);
		}
		
		if(bean==null){
			
			writer.print("<script language=javascript>alert('原密码错误，修改失败！');window.location.href='password.do';</script>");
		
			
		}else{
			
			bean.setPassword(password2);
			
			userService.updateBean(bean);
			
			writer.print("<script language=javascript>alert('修改成功,请重新登录');window.location.href='loginout.do';</script>");
			
		}
		
		
	}
	
	
	//跳转到个人信息维护页面
	@RequestMapping("/userupdate.do")
	public String userupdate(HttpServletRequest request){

		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		
		User bean = userService.selectBeanById(user.getId());
		
		request.setAttribute("bean", bean);

		return "userupdate.jsp";

	}
	
	
	//个人信息维护操作
	@RequestMapping("/userupdate2.do")
	public void userupdate2(HttpServletRequest request,HttpServletResponse response,String name,String phone,String address){
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		
		User bean = userService.selectBeanById(user.getId());

		
		bean.setPhone(phone);
		bean.setName(name);
		
		userService.updateBean(bean);
		
		writer.print("<script language=javascript>alert('修改成功');window.location.href='userupdate.do';</script>");


	}
	
	
	//跳转到上传教学资源页面
	@RequestMapping("/ziyuanadd.do")
	public String ziyuanadd(HttpServletRequest request,HttpServletResponse response) {
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		if (user == null) {
			writer.print("<script  language='javascript'>alert('请先登录');window.location.href='login.do';</script>");
			return  null;
		}
	
		return "ziyuanadd.jsp";
		
	}
	
	
	//上传教学资源操作
	@RequestMapping("/ziyuanadd2.do")
	public void ziyuanadd2(HttpServletRequest request,HttpServletResponse response,MultipartFile prodFile) throws IOException{
		
		PrintWriter writer = this.getPrintWriter(response);
	
		if(prodFile==null || prodFile.getSize()<=0 ){
			this.getPrintWriter(response).print("<script language=javascript>alert('资源文件不能为空');" +
			"window.location.href='ziyuanadd.do';</script>");
			return;
		}
		
		String path =  Util.uploadFile(request, prodFile);
		
		String intro = request.getParameter("intro");
		String zname = request.getParameter("zname");
		
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		Ziyuan bean = new Ziyuan();;
		
		bean.setCtime(Util.getRiqi());
		bean.setIntro(intro);
		bean.setKname(user.getKname());
		bean.setName(user.getName());

		bean.setUsername(user.getUsername());
		bean.setZname(zname);
		
		bean.setPath(path);
		

		ziyuanService.insertBean(bean);
		
		
		writer.print("<script  language='javascript'>alert('上传成功');window.location.href='ziyuanlist.do'; </script>");
		
	
	}
	
	
	
	//我的教学资源
	@RequestMapping("/ziyuanlist.do")
	public String ziyuanlist(HttpServletRequest request,HttpServletResponse response,String pagenum,String zname){
		
		
		String url = "ziyuanlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_ziyuan where  ");
		
		//查询条件返回页面
		if (zname != null && !"".equals(zname)) {

			sb.append(" zname like '%"+zname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("zname", zname);
		}
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		sb.append(" username='"+user.getUsername()+"' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Ziyuan>> map = ziyuanService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Ziyuan> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		return "ziyuanlist.jsp";

	}
	
	
	//删除教学资源操作
	@RequestMapping("/ziyuandelete.do")
	public void ziyuandelete(HttpServletResponse response,int id){

		ziyuanService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='ziyuanlist.do';</script>");
	}
	
	
	//教学资源详情页面
	@RequestMapping("/ziyuanshow.do")
	public String ziyuanshow(HttpServletRequest request,int id){

		Ziyuan bean = ziyuanService.selectData(" select * from t_ziyuan where id= "+id).get(0);

		request.setAttribute("bean", bean);

		return "ziyuanshow.jsp";

	}
	
	
	//教学资源
	@RequestMapping("/ziyuanlist2.do")
	public String ziyuanlist2(HttpServletRequest request,HttpServletResponse response,String pagenum,String zname,String kname){
		
		
		String url = "ziyuanlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_ziyuan where  ");
		
		//查询条件返回页面
		if (zname != null && !"".equals(zname)) {

			sb.append(" zname like '%"+zname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("zname", zname);
		}
		
		if (kname != null && !"".equals(kname)) {

			sb.append(" kname ='"+kname+"' ");
			sb.append(" and ");
			
			request.setAttribute("kname", kname);
		}
		
		
		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Ziyuan>> map = ziyuanService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Ziyuan> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "ziyuanlist2.jsp";

	}
	
	
	
	
	
	//跳转到上传教学视频页面
	@RequestMapping("/shipinadd.do")
	public String shipinadd(HttpServletRequest request,HttpServletResponse response) {
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		if (user == null) {
			writer.print("<script  language='javascript'>alert('请先登录');window.location.href='login.do';</script>");
			return  null;
		}
	
		return "shipinadd.jsp";
		
	}
	
	
	//上传教学视频操作
	@RequestMapping("/shipinadd2.do")
	public void shipinadd2(HttpServletRequest request,HttpServletResponse response,MultipartFile prodFile) throws IOException{
		
		PrintWriter writer = this.getPrintWriter(response);
	
		if(prodFile==null || prodFile.getSize()<=0 ){
			this.getPrintWriter(response).print("<script language=javascript>alert('视频文件不能为空');" +
			"window.location.href='shipinadd.do';</script>");
			return;
		}
		
		long size = 30*1024*1024;//最大30M
		
		if(prodFile.getSize()>size){
			this.getPrintWriter(response).print("<script language=javascript>alert('上传失败，视频文件不能大于30M');" +
			"window.location.href='shipinadd.do';</script>");
			return;
		}

		
		String path =  Util.uploadFile(request, prodFile);
		
		String intro = request.getParameter("intro");
		String sname = request.getParameter("sname");
		
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		Shipin bean = new Shipin();;
		
		bean.setCtime(Util.getRiqi());
		bean.setIntro(intro);
		bean.setKname(user.getKname());
		bean.setName(user.getName());

		bean.setUsername(user.getUsername());
		bean.setSname(sname);
		
		bean.setPath(path);
		

		shipinService.insertBean(bean);
		
		
		writer.print("<script  language='javascript'>alert('上传成功');window.location.href='shipinlist.do'; </script>");
		
	
	}
	
	
	
	//我的教学视频
	@RequestMapping("/shipinlist.do")
	public String shipinlist(HttpServletRequest request,HttpServletResponse response,String pagenum,String sname){
		
		
		String url = "shipinlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_shipin where  ");
		
		//查询条件返回页面
		if (sname != null && !"".equals(sname)) {

			sb.append(" sname like '%"+sname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("sname", sname);
		}
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		sb.append(" username='"+user.getUsername()+"' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Shipin>> map = shipinService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Shipin> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		return "shipinlist.jsp";

	}
	
	
	//删除教学视频操作
	@RequestMapping("/shipindelete.do")
	public void shipindelete(HttpServletResponse response,int id){

		shipinService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='shipinlist.do';</script>");
	}
	
	
	//教学视频详情页面
	@RequestMapping("/shipinshow.do")
	public String shipinshow(HttpServletRequest request,int id){

		Shipin bean = shipinService.selectData(" select * from t_shipin where id= "+id).get(0);

		request.setAttribute("bean", bean);

		return "shipinshow.jsp";

	}
	
	
	
	//在线播放
	@RequestMapping("/shipinshow2.do")
	public String shipinshow2(HttpServletRequest request,int id){

		Shipin bean = shipinService.selectData(" select * from t_shipin where id= "+id).get(0);

		request.setAttribute("bean", bean);

		return "shipinshow2.jsp";

	}
	
	
	//教学视频
	@RequestMapping("/shipinlist2.do")
	public String shipinlist2(HttpServletRequest request,HttpServletResponse response,String pagenum,String zname,String kname){
		
		
		String url = "shipinlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_shipin where  ");
		
		//查询条件返回页面
		if (zname != null && !"".equals(zname)) {

			sb.append(" zname like '%"+zname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("zname", zname);
		}
		
		if (kname != null && !"".equals(kname)) {

			sb.append(" kname ='"+kname+"' ");
			sb.append(" and ");
			
			request.setAttribute("kname", kname);
		}
		
		
		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Shipin>> map = shipinService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Shipin> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "shipinlist2.jsp";

	}
	
	
	
	//跳转到在线提问
	@RequestMapping("/dayiadd.do")
	public String dayiadd(HttpServletRequest request,HttpServletResponse response) {
		
		PrintWriter writer = this.getPrintWriter(response);
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		if (user == null) {
			writer.print("<script  language='javascript'>alert('请先登录');window.location.href='login.do';</script>");
			return  null;
		}
		
		Map<String,List<User>> usermap = userService.selectBeanMap(1, 100, ".", " select * from t_user where role=2 ");
	
		String pagerinfo = usermap.keySet().iterator().next();
		List<User> userlist = usermap.get(pagerinfo);
		
		request.setAttribute("userlist", userlist);
		
		return "dayiadd.jsp";
		
	}
	
	
	//在线提问操作
	@RequestMapping("/dayiadd2.do")
	public void dayiadd2(HttpServletRequest request,HttpServletResponse response ) throws IOException{
		
		PrintWriter writer = this.getPrintWriter(response);
	

		
		String dbiaoti = request.getParameter("dbiaoti");
		String neirong = request.getParameter("neirong");
		
		String touserid = request.getParameter("touserid");
		
		User touser = userService.selectBeanById(Integer.parseInt(touserid));
		
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		Dayi bean = new Dayi();;
		
		bean.setCtime(Util.getRiqi());
		bean.setDbiaoti(dbiaoti);
		bean.setFromname(user.getName());
		bean.setFromusername(user.getUsername());
		bean.setKname(touser.getKname());
		bean.setNeirong(neirong);
		bean.setStatus("未回答");
		bean.setToname(touser.getName());
		bean.setTouserid(Integer.parseInt(touserid));
		bean.setTousername(touser.getUsername());
		

		dayiService.insertBean(bean);
		
		
		writer.print("<script  language='javascript'>alert('操作成功');window.location.href='dayilist.do'; </script>");
		
	
	}
	
	
	
	//我的问题
	@RequestMapping("/dayilist.do")
	public String dayilist(HttpServletRequest request,HttpServletResponse response,String pagenum,String dbiaoti,String kname){
		
		
		String url = "dayilist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_dayi where  ");
		
		//查询条件返回页面
		if (dbiaoti != null && !"".equals(dbiaoti)) {

			sb.append(" dbiaoti like '%"+dbiaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("dbiaoti", dbiaoti);
		}
		
		if (kname != null && !"".equals(kname)) {

			sb.append(" kname = '"+kname+"' ");
			sb.append(" and ");
			
			request.setAttribute("kname", kname);
		}
		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		sb.append(" fromusername='"+user.getUsername()+"' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Dayi>> map = dayiService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Dayi> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "dayilist.jsp";

	}
	
	
	//删除操作
	@RequestMapping("/dayidelete.do")
	public void dayidelete(HttpServletResponse response,int id){

		dayiService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='dayilist.do';</script>");
	}
	
	
	//详情页面
	@RequestMapping("/dayishow.do")
	public String dayishow(HttpServletRequest request,int id){

		Dayi bean = dayiService.selectData(" select * from t_dayi where id= "+id).get(0);

		request.setAttribute("bean", bean);

		return "dayishow.jsp";

	}
	
	
	
	//在线问题
	@RequestMapping("/dayilist2.do")
	public String dayilist2(HttpServletRequest request,HttpServletResponse response,String pagenum,String dbiaoti,String kname){
		
		
		String url = "dayilist2.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_dayi where  ");
		
		//查询条件返回页面
		if (dbiaoti != null && !"".equals(dbiaoti)) {

			sb.append(" dbiaoti like '%"+dbiaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("dbiaoti", dbiaoti);
		}
		
		if (kname != null && !"".equals(kname)) {

			sb.append(" kname = '"+kname+"' ");
			sb.append(" and ");
			
			request.setAttribute("kname", kname);
		}
		

		sb.append(" status='已回答' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Dayi>> map = dayiService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Dayi> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "dayilist2.jsp";

	}
	
	
	//待回答问题
	@RequestMapping("/dayilist3.do")
	public String dayilist3(HttpServletRequest request,HttpServletResponse response,String pagenum,String dbiaoti){
		
		
		String url = "dayilist3.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_dayi where  ");
		
		//查询条件返回页面
		if (dbiaoti != null && !"".equals(dbiaoti)) {

			sb.append(" dbiaoti like '%"+dbiaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("dbiaoti", dbiaoti);
		}
		

		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		sb.append(" tousername='"+user.getUsername()+"' and status='未回答' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Dayi>> map = dayiService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Dayi> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "dayilist3.jsp";

	}
	
	//删除操作
	@RequestMapping("/dayidelete2.do")
	public void dayidelete2(HttpServletResponse response,int id){

		dayiService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='dayilist3.do';</script>");
	}
	
	
	//跳转到回答问题页面
	@RequestMapping("/dayiupdate.do")
	public String dayiupdate(HttpServletRequest request,int id){

		Dayi bean = dayiService.selectData(" select * from t_dayi where id= "+id).get(0);
		
		request.setAttribute("bean", bean);

		request.setAttribute("url", "dayiupdate2.do?id="+id);

		return "dayiupdate.jsp";

	}

	
	//回答问题操作
	@RequestMapping("/dayiupdate2.do")
	public void dayiupdate2(HttpServletRequest request,HttpServletResponse response,int id){

		
		String huida = request.getParameter("huida");
		
		Dayi bean = dayiService.selectData(" select * from t_dayi where id= "+id).get(0);
		
		bean.setHtime(Util.getRiqi());
		bean.setHuida(huida);
		bean.setStatus("已回答");
		
		dayiService.updateBean(bean);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='dayilist3.do';</script>");
	}
	
	
	
	//待回答问题
	@RequestMapping("/dayilist4.do")
	public String dayilist4(HttpServletRequest request,HttpServletResponse response,String pagenum,String dbiaoti){
		
		
		String url = "dayilist4.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_dayi where  ");
		
		//查询条件返回页面
		if (dbiaoti != null && !"".equals(dbiaoti)) {

			sb.append(" dbiaoti like '%"+dbiaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("dbiaoti", dbiaoti);
		}
		

		
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("qiantai");
		
		sb.append(" tousername='"+user.getUsername()+"' and status='已回答' order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Dayi>> map = dayiService.selectBeanMap(currentpage,10,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Dayi> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);
		
		List<Course> kclist = kechengService.selectData(" select * from t_kecheng ");

		request.setAttribute("kclist", kclist);
		
		return "dayilist4.jsp";

	}
	
}












